package com.zs4sdk.extra;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.common.library.util.ActivityHelper;
import com.zs4gamesdk.R;

/**
 * 
 * function: 初始化传参
 * 
 * @ author: aXiBa
 */
public class Zs4GameInfo {

	private Context ctx;

	private int appId;
	
	private String appKey;

	private int appCompany;
	private String channel;

	private static String readAppkey(Context context) {
		try {
			ApplicationInfo appInfo = context.getPackageManager()
					.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			if (appInfo != null) {
				return appInfo.metaData.getString("com.zs4game.appkey");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	private static int readAppId(Context context) {
		try {
			ApplicationInfo appInfo = context.getPackageManager()
					.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
			if (appInfo != null) {
				return appInfo.metaData.getInt("com.zs4game.appid");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return -1;
	}
//	private String packagename;
	public Zs4GameInfo(Context context){
		ctx = context;
		appId =  readAppId(context);
		appKey = readAppkey(context);
		if(appId == -1){
			ActivityHelper.showLongToast(context,context.getString(R.string.zs4Game_right_appid));
		}
		if(appKey == null){
			ActivityHelper.showLongToast(context,context.getString(R.string.zs4Game_right_appkey));
		}
	}

	public Context getCtx() {
		return ctx;
	}

	public void setCtx(Context ctx) {
		this.ctx = ctx;
	}

	public int getAppId() {
		return appId;
	}

	public void setAppId(int appId) {
		this.appId = appId;
	}

	public String getAppKey() {
		return appKey;
	}

	public void setAppKey(String appKey) {
		this.appKey = appKey;
	}

	public int getAppCompany() {
		return appCompany;
	}

	public void setAppCompany(int appCompany) {
		this.appCompany = appCompany;
	}

//	public String getPackagename() {
//		return packagename;
//	}
//
//	public void setPackagename(String packagename) {
//		this.packagename = packagename;
//	}


	public String getChannel() {
		return channel;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}
}
